<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./css/index.css">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.4/jquery.js"></script>
</head>
<body>
    <!-- <img src="./images/baidu.png" alt=""> -->
    <!-- <form action="http://localhost:3002" method="post"> -->
        用户名：<input type="text" name="username" id="username">
        密码：<input type="password" name="password" id="password">
        <!-- <input type="submit" value="submit"> -->
    <!-- </form> -->

    <div>
        <button id="ajaxBtn">ajax</button>
    </div>
    <ul id="hello">

    </ul>
    
    <script>
        $("#ajaxBtn").click(()=>{
            let username = $('#username').val()
            let password = $('#password').val()
            $.post({
                url:"http://localhost:3000",
                data:{username,password},
                dataType:"json",  //这里的意思是，post返回回去的数据类型是json格式的
                success:function(res){
                    console.log(res);
                    $("#hello").html(res.username);
                }
            })
        })
    </script>
</body>
</html>